package com.wn.service;

/**
 * ????????
 */
import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import com.wn.util.HttpUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class Station2sDemo {
	public final static String host = "http://jisutrain.market.alicloudapi.com";
	public static final String end = "北京";
	public static final String ishigh = "0";
	public static final String start = "上海";

	public static void main(String[] args) throws Exception {
		String path = "/train/station2s";
		Map<String, String> headers = new HashMap<String, String>();
		headers.put("Authorization", "90d30269a4264094bce3f24165f43b14");

		// ?????query
		Map<String, String> querys = new HashMap<String, String>();
		querys.put("end", end);
		querys.put("ishigh", ishigh);
		querys.put("start", start);
		try {
			HttpResponse response = HttpUtils.doGet(host, path, "GET", headers, querys);
			// response Head
			 System.out.println("11111"+response.toString());
			String result = EntityUtils.toString(response.getEntity());
			System.out.println("2222"+result);
			JSONObject json = JSONObject.fromObject(result);
			System.out.println(json+"************");
			if (json.getInt("status") != 0) {
				System.out.println(json.getString("msg"));
			} else {
				JSONArray resultarr = json.optJSONArray("result");
				for (int i = 0; i < resultarr.size(); i++) {
					JSONObject obj = (JSONObject) resultarr.opt(i);
					String trainno = obj.getString("trainno");
					String type = obj.getString("type");
					String station = obj.getString("station");
					String endstation = obj.getString("endstation");
					String departuretime = obj.getString("departuretime");
					String arrivaltime = obj.getString("arrivaltime");
					String sequenceno = obj.getString("sequenceno");
					String costtime = obj.getString("costtime");
					String distance = obj.getString("distance");
					String isend = obj.getString("isend");
					String pricesw = obj.getString("pricesw");
					String pricetd = obj.getString("pricetd");
					String pricegr1 = obj.getString("pricegr1");
					String pricegr2 = obj.getString("pricegr2");
					String pricerw1 = obj.getString("pricerw1");
					String pricerw2 = obj.getString("pricerw2");
					String priceyw1 = obj.getString("priceyw1");
					String priceyw2 = obj.getString("priceyw2");
					String priceyw3 = obj.getString("priceyw3");
					String priceyd = obj.getString("priceyd");
					String priceed = obj.getString("priceed");
					String pricerz = "";
					if (obj.has("pricerz")) {
						pricerz = obj.getString("pricerz");
					}
					String priceyz = "";
					if (obj.has("priceyz")) {
						priceyz = obj.getString("priceyz");
					}
					System.out.println(trainno + " " + type + " " + station + " " + endstation + " " + departuretime
							+ " " + arrivaltime + " " + sequenceno + " " + costtime + " " + distance + " " + isend + " "
							+ pricesw + " " + pricetd + " " + pricegr1 + " " + pricegr2 + " " + pricerw1 + " "
							+ pricerw2 + " " + priceyw1 + " " + priceyw2 + " " + priceyw3 + " " + priceyd + " "
							+ priceed + " " + pricerz + " " + priceyz);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
